#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int T,n,a[200009],color[200009],ans;
void dfs(int step){
    if(step>=n){
        int num=0;
        for(int i=1;i<=n;++i){
            for(int j=i-1;j>=1;--j){
                if(a[i]==a[j]){
                    num+=a[i];
                    break;
                }
            }
        }
        ans=max(ans,num);
        return;
    }
    color[step]=0;
    dfs(step+1);
    color[step]=1;
    dfs(step+1);
}
int main(){
    IOS
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>T;
    while(T--){
        ans=0;
        cin>>n;
        for(int i=1;i<=n;++i)
            cin>>a[i];
        dfs(1);
        cout<<ans<<endl;
    }
    return 0;
}
